<?php

$envFile = __DIR__ . '/.env';
if (file_exists($envFile)) {
    $file = fopen($envFile, 'r');
    while(!feof($file) && ($line = fgets($file)) !== false) {
        if (empty($line)) {
            continue;
        }
        if (strpos(trim($line), '#') === 0) {
            continue;
        }
        $result = explode('=', $line);
        if (count($result) == 2) {
            list($key, $value) = explode('=', $line);
        } else {
            $key = array_shift($result);
            $value = implode('=', $result);
        }
        if (!empty($value) && !empty($key)) {
            defined(trim($key)) or define(trim($key), trim($value));
        }
    }

    fclose($file);
}
